package com.situ.saveqq;

import android.content.Context;
import android.content.SharedPreferences;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * 把账号和密码保存到SharedPreference
 */
public class SPSaveQQ {

    /**
     * 保存用户信息
     * @param context Android 的上下文环境
     * @param number  账号
     * @param password  密码
     * @return   true:保存成功， false：保存失败
     */
    public static boolean saveUserInfo(Context context, String number, String password) {
        SharedPreferences sharedPreferences = context.getSharedPreferences("data", Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putString("number", number);
        editor.putString("password", password);
        editor.commit();
        return true;
    }

    public static Map<String, String> getUserInfo(Context context) {
        SharedPreferences sharedPreferences = context.getSharedPreferences("data", Context.MODE_PRIVATE);
        String number =  sharedPreferences.getString("number", "");
        String password = sharedPreferences.getString("password", "");
        Map<String, String> map = new HashMap<>();
        map.put("number", number);
        map.put("password", password);
        return map;
    }


}
